package com.justgame.project.cloud.common.enums;


import com.justgame.project.cloud.common.util.TimeUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Date;

/**
 * 时间枚举
 */
@Getter
@AllArgsConstructor
@SuppressWarnings("all")
public enum TimeEnum {
    /* 秒 */
    SECOND,
    /* 分 */
    MINUTE,
    /* 时 */
    HOUR,
    /* 天 */
    DAY;

    public long getTime(int val) {
        long timeStamp = val * 1000L;
        switch (this) {
            case SECOND:
                return timeStamp;
            case MINUTE:
                return timeStamp * 60L;
            case HOUR:
                return timeStamp * 60 * 60L;
            case DAY:
                return timeStamp * 60 * 60 * 24L;
        }
        return 0L;
    }

    /**
     * 获取从现在开始，**时长 以后/以前 的日期
     *
     * @return Date
     */
    public Date calculateEndDateFromNow(int val) {
        long timeStamp = val * 1000L;
        switch (this) {
            case SECOND:
                break;
            case MINUTE:
                timeStamp *= 60L;
                break;
            case HOUR:
                timeStamp *= 60 * 60L;
                break;
            case DAY:
                timeStamp *= 60 * 60 * 24L;
                break;
        }
        return new Date(System.currentTimeMillis() + timeStamp);
    }

    /**
     * 从开始日期推算处结束日期
     * @param startDate 开始日期
     * @param val
     * @return
     */
    public Date calculateEndDate(Date startDate,int val) {
        long timeStamp = val * 1000L;
        switch (this) {
            case SECOND:
                break;
            case MINUTE:
                timeStamp *= 60L;
                break;
            case HOUR:
                timeStamp *= 60 * 60L;
                break;
            case DAY:
                timeStamp *= 60 * 60 * 24L;
                break;
        }
        return new Date(startDate.getTime() + timeStamp);
    }


    /**
     * 获取从现在开始，**时长 以后/以前 的日期
     *
     * @return String
     */
    public String calculateEndDateString(int val) {
        return TimeUtil.simpleDate(calculateEndDateFromNow(val));
    }

    /**
     * 获取从现在开始，**时长 以后/以前 的日期
     *
     * @return Long
     */
    public long calculateEndTimeFromNow(int val) {
        long timeStamp = val * 1000L;
        switch (this) {
            case SECOND:
                break;
            case MINUTE:
                timeStamp *= 60L;
                break;
            case HOUR:
                timeStamp *= 60 * 60L;
                break;
            case DAY:
                timeStamp *= 60 * 60 * 24L;
                break;
        }
        return System.currentTimeMillis() + timeStamp;
    }

}
